﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using JAMK.ICT;

namespace SimpleDataBinding
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    Henkilö[] porukka;
    int laskuri = 0;
    public MainWindow()
    {
      InitializeComponent();
      porukka = JAMK.ICT.TestiHenkilöt.AnnaKolmeHenkilöä();
      //DataContextin määrittely
      myGrid.DataContext = porukka[laskuri];
      dgData.ItemsSource = porukka;
    }

    private void btnForward_Click(object sender, RoutedEventArgs e)
    {
      //muutetaan dataconteksi yksittäinen olio kokoelmasta
      if (laskuri < porukka.Length - 1)
      {
        laskuri++;
        myGrid.DataContext = porukka[laskuri];
      }
    }

    private void btnBackward_Click(object sender, RoutedEventArgs e)
    {
      if (laskuri > 0)
      {
        laskuri--;
      }
      //else
      //{
      //  laskuri = 0;
      //}
      myGrid.DataContext = porukka[laskuri];
    }

    private void dgData_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // Muutetaa stackpanelin datasource -> sp:ssa olevat perivät sp:n datasource
        int i = dgData.SelectedIndex;
        if (i > -1)
            mySP.DataContext = porukka[i];

    }
  }
}
